package com.tanhua.recommend.handler;

import com.tanhua.domain.mongo.Publish;
import org.springframework.stereotype.Component;

/**
 * 发布动态处理实现类
 */
@Component
public class DianzanPublishScoreHandler implements PublishScoreHandler {

    private Integer type = 3;

    @Override
    public Boolean shouldHandle(Integer type) {
        if (this.type == type) {
            return true;
        }
        return false;
    }

    @Override
    public Double handle(Publish publish) {
        Double score = 0D;
        if (publish.getTextContent().length() < 50) {  // 文字长度小于50
            score += 1;
        } else if (publish.getTextContent().length() < 100) { // 文字长度大于等于50，小于100
            score += 2;
        } else {
            score += 3;
        }
        // 一张图片加一分
        if (publish.getMedias() != null) {
            score += publish.getMedias().size();
        }
        return score;
    }
}
